package com.steak.transaction.execute;

import com.steak.transaction.result.R;
import com.steak.transaction.service.IntegralService;
import com.steak.transaction.service.OrderService;
import com.steak.transaction.service.StockService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * @author 刘牌
 * @Title:
 * @date 2022/3/112:59
 */
@Component
@AllArgsConstructor
public class PlaceOrderExecute {
    private final OrderService orderRpcService;
    private final IntegralService integralService;
    private final StockService stockService;

    public R execute(final Integer userId ,final Integer commodityId){
        R orderR = orderRpcService.saveOrder(userId, commodityId);
        R integralR = integralService.increaseIntegral(userId, 5);
        R stockR = stockService.decreaseStock(commodityId);
        return R.builder().code(200).msg("place order success").build();
    }

    public R getUser() {
       return stockService.get();
    }

    public R defaultDatasource() {
        return stockService.defaultDatasource();
    }
}
